////
//// Source code recreated from a .class file by IntelliJ IDEA
//// (powered by FernFlower decompiler)
////
//
//package com.zrc.japktool.core.apkmerge.apkeditor;
//
//import java.util.Iterator;
//import java.util.List;
//
//public class Res_value {
//    public static final int TYPE_NULL = 0;
//    public static final int TYPE_REFERENCE = 1;
//    public static final int TYPE_ATTRIBUTE = 2;
//    public static final int TYPE_STRING = 3;
//    public static final int TYPE_FLOAT = 4;
//    public static final int TYPE_DIMENSION = 5;
//    public static final int TYPE_FRACTION = 6;
//    public static final int TYPE_DYNAMIC_REFERENCE = 7;
//    public static final int TYPE_FIRST_INT = 16;
//    public static final int TYPE_INT_DEC = 16;
//    public static final int TYPE_INT_HEX = 17;
//    public static final int TYPE_INT_BOOLEAN = 18;
//    public static final int TYPE_FIRST_COLOR_INT = 28;
//    public static final int TYPE_INT_COLOR_ARGB8 = 28;
//    public static final int TYPE_INT_COLOR_RGB8 = 29;
//    public static final int TYPE_INT_COLOR_ARGB4 = 30;
//    public static final int TYPE_INT_COLOR_RGB4 = 31;
//    public static final int TYPE_LAST_COLOR_INT = 31;
//    public static final int TYPE_LAST_INT = 31;
//    public int data;
//    public String raw;
//    public List<StyleSpan> styles;
//    public int type;
//
//    public Res_value() {
//    }
//
//    public Res_value(int type, int data, String raw, List<StyleSpan> styles) {
//        this.type = type;
//        this.data = data;
//        this.raw = raw;
//        this.styles = styles;
//    }
//
//    public static Res_value newStringValue(String str) {
//        return new Res_value(3, -1, str, (List)null);
//    }
//
//    String toXml() {
//        StringBuilder sb = new StringBuilder();
//
//        for(int i = 0; i < this.raw.length(); ++i) {
//            Iterator var3 = this.styles.iterator();
//
//            StyleSpan style;
//            while(var3.hasNext()) {
//                style = (StyleSpan)var3.next();
//                if (style.start == i) {
//                    sb.append("<").append(style.name).append(">");
//                }
//            }
//
//            sb.append(this.raw.charAt(i));
//            var3 = this.styles.iterator();
//
//            while(var3.hasNext()) {
//                style = (StyleSpan)var3.next();
//                if (style.end == i) {
//                    sb.append("</").append(style.name).append(">");
//                }
//            }
//        }
//
//        return sb.toString();
//    }
//
//    public String toString() {
//        switch(this.type) {
//        case 0:
//            return this.data == 0 ? "[undefined]" : "[empty]";
//        case 1:
//            return String.format("@0x%08x", this.data);
//        case 2:
//            return String.format("?0x%08x", this.data);
//        case 3:
//            return this.styles != null ? this.toXml() : this.raw;
//        case 4:
//            return String.valueOf(Float.intBitsToFloat(this.data));
//        case 5:
//        case 6:
//        case 7:
//        case 8:
//        case 9:
//        case 10:
//        case 11:
//        case 12:
//        case 13:
//        case 14:
//        case 15:
//        case 16:
//        case 17:
//        case 19:
//        case 20:
//        case 21:
//        case 22:
//        case 23:
//        case 24:
//        case 25:
//        case 26:
//        case 27:
//        default:
//            if (this.type >= 16 && this.type <= 31) {
//                return String.valueOf(this.data);
//            }
//
//            return String.format("{t=0x%02x d=0x%08x}", this.type, this.data);
//        case 18:
//            return String.valueOf(this.data != 0);
//        case 28:
//            return String.format("#%08x", this.data);
//        case 29:
//            return String.format("#%06x", this.data & 16777215);
//        case 30:
//            return String.format("#%04x", this.data & '\uffff');
//        case 31:
//            return String.format("#%03x", this.data & 4095);
//        }
//    }
//
//    public static Res_value newTrue() {
//        return new Res_value(18, -1, (String)null, (List)null);
//    }
//
//    public static Res_value newFalse() {
//        return new Res_value(18, 0, (String)null, (List)null);
//    }
//
//    public static Res_value newDecInt(int i) {
//        return new Res_value(16, i, (String)null, (List)null);
//    }
//
//    public static Res_value newHexInt(int i) {
//        return new Res_value(17, i, (String)null, (List)null);
//    }
//
//    public static Res_value newReference(int i) {
//        return new Res_value(1, i, (String)null, (List)null);
//    }
//
//    public static Res_value newFloat(float i) {
//        return new Res_value(4, Float.floatToIntBits(i), (String)null, (List)null);
//    }
//
//    public static Res_value newUnDefined() {
//        return new Res_value(0, 0, (String)null, (List)null);
//    }
//
//    public static Res_value newEmpty() {
//        return new Res_value(0, 1, (String)null, (List)null);
//    }
//
//    public static Res_value newColorARGB8(int a, int r, int g, int b) {
//        int value = (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0;
//        return new Res_value(28, value, (String)null, (List)null);
//    }
//
//    public static Res_value newColorRGB8(int r, int g, int b) {
//        int value = (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0;
//        return new Res_value(29, value, (String)null, (List)null);
//    }
//
//    public static Res_value newColorARGB4(int a, int r, int g, int b) {
//        int value = (a & 15) << 12 | (r & 15) << 8 | (g & 15) << 4 | (b & 15) << 0;
//        return new Res_value(30, value, (String)null, (List)null);
//    }
//
//    public static Res_value newColorRGB4(int r, int g, int b) {
//        int value = (r & 15) << 8 | (g & 15) << 4 | (b & 15) << 0;
//        return new Res_value(31, value, (String)null, (List)null);
//    }
//}




package com.zrc.japktool.apk.merge.apkeditor;

import java.util.Iterator;
import java.util.List;

public class Res_value {
    public static final int TYPE_NULL = 0;
    public static final int TYPE_REFERENCE = 1;
    public static final int TYPE_ATTRIBUTE = 2;
    public static final int TYPE_STRING = 3;
    public static final int TYPE_FLOAT = 4;
    public static final int TYPE_DIMENSION = 5;
    public static final int TYPE_FRACTION = 6;
    public static final int TYPE_DYNAMIC_REFERENCE = 7;
    public static final int TYPE_FIRST_INT = 16;
    public static final int TYPE_INT_DEC = 16;
    public static final int TYPE_INT_HEX = 17;
    public static final int TYPE_INT_BOOLEAN = 18;
    public static final int TYPE_FIRST_COLOR_INT = 28;
    public static final int TYPE_INT_COLOR_ARGB8 = 28;
    public static final int TYPE_INT_COLOR_RGB8 = 29;
    public static final int TYPE_INT_COLOR_ARGB4 = 30;
    public static final int TYPE_INT_COLOR_RGB4 = 31;
    public static final int TYPE_LAST_COLOR_INT = 31;
    public static final int TYPE_LAST_INT = 31;

    // 维度单位常量
    public static final int COMPLEX_UNIT_SHIFT = 0;
    public static final int COMPLEX_UNIT_MASK = 0xf;
    public static final int COMPLEX_UNIT_PX = 0;
    public static final int COMPLEX_UNIT_DIP = 1;
    public static final int COMPLEX_UNIT_SP = 2;
    public static final int COMPLEX_UNIT_PT = 3;
    public static final int COMPLEX_UNIT_IN = 4;
    public static final int COMPLEX_UNIT_MM = 5;

    // 分数单位常量
    public static final int FRACTION_FLAG_SHIFT = 8;
    public static final int FRACTION_FLAG_MASK = 0x3;
    public static final int FRACTION_FLAG_NORMAL = 0;
    public static final int FRACTION_FLAG_PARENT = 1;

    public int data;
    public String raw;
    public List<StyleSpan> styles;
    public int type;

    public Res_value() {
    }

    public Res_value(int type, int data, String raw, List<StyleSpan> styles) {
        this.type = type;
        this.data = data;
        this.raw = raw;
        this.styles = styles;
    }

    public static Res_value newStringValue(String str) {
        return new Res_value(3, -1, str, (List)null);
    }

    String toXml() {
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < this.raw.length(); ++i) {
            Iterator var3 = this.styles.iterator();

            StyleSpan style;
            while(var3.hasNext()) {
                style = (StyleSpan)var3.next();
                if (style.start == i) {
                    sb.append("<").append(style.name).append(">");
                }
            }

            sb.append(this.raw.charAt(i));
            var3 = this.styles.iterator();

            while(var3.hasNext()) {
                style = (StyleSpan)var3.next();
                if (style.end == i) {
                    sb.append("</").append(style.name).append(">");
                }
            }
        }

        return sb.toString();
    }

    public String toString() {
        switch(this.type) {
            case 0:
                return this.data == 0 ? "[undefined]" : "[empty]";
            case 1:
                return String.format("@0x%08x", this.data);
            case 2:
                return String.format("?0x%08x", this.data);
            case 3:
                return this.styles != null ? this.toXml() : this.raw;
            case 4:
                return String.valueOf(Float.intBitsToFloat(this.data));
            case 5:
                return getDimensionString();
            case 6:
                return getFractionString();
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
                return String.valueOf(this.data);
            case 17:
                return String.format("0x%08x", this.data);
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            default:
                if (this.type >= 16 && this.type <= 31) {
                    return String.valueOf(this.data);
                }
                return String.format("{t=0x%02x d=0x%08x}", this.type, this.data);
            case 18:
                return String.valueOf(this.data != 0);
            case 28:
                return String.format("#%08x", this.data);
            case 29:
                return String.format("#%06x", this.data & 16777215);
            case 30:
                return String.format("#%04x", this.data & '\uffff');
            case 31:
                return String.format("#%03x", this.data & 4095);
        }
    }

    // 处理维度类型
    private String getDimensionString() {
        int unit = (data >> COMPLEX_UNIT_SHIFT) & COMPLEX_UNIT_MASK;
        float value = Float.intBitsToFloat(data & 0xFFFFFF00);

        String unitStr;
        switch (unit) {
            case COMPLEX_UNIT_PX: unitStr = "px"; break;
            case COMPLEX_UNIT_DIP: unitStr = "dp"; break;
            case COMPLEX_UNIT_SP: unitStr = "sp"; break;
            case COMPLEX_UNIT_PT: unitStr = "pt"; break;
            case COMPLEX_UNIT_IN: unitStr = "in"; break;
            case COMPLEX_UNIT_MM: unitStr = "mm"; break;
            default: unitStr = "unknown";
        }

        return String.format("%f%s", value, unitStr);
    }

    // 处理分数类型
    private String getFractionString() {
        int flag = (data >> FRACTION_FLAG_SHIFT) & FRACTION_FLAG_MASK;
        float value = Float.intBitsToFloat(data & 0xFFFF00FF);

        String flagStr;
        switch (flag) {
            case FRACTION_FLAG_NORMAL: flagStr = "%"; break;
            case FRACTION_FLAG_PARENT: flagStr = "%p"; break;
            default: flagStr = "%unknown";
        }

        return String.format("%f%s", value, flagStr);
    }

    public static Res_value newTrue() {
        return new Res_value(18, -1, (String)null, (List)null);
    }

    public static Res_value newFalse() {
        return new Res_value(18, 0, (String)null, (List)null);
    }

    public static Res_value newDecInt(int i) {
        return new Res_value(16, i, (String)null, (List)null);
    }

    public static Res_value newHexInt(int i) {
        return new Res_value(17, i, (String)null, (List)null);
    }

    public static Res_value newReference(int i) {
        return new Res_value(1, i, (String)null, (List)null);
    }

    public static Res_value newFloat(float i) {
        return new Res_value(4, Float.floatToIntBits(i), (String)null, (List)null);
    }

    public static Res_value newUnDefined() {
        return new Res_value(0, 0, (String)null, (List)null);
    }

    public static Res_value newEmpty() {
        return new Res_value(0, 1, (String)null, (List)null);
    }

    public static Res_value newColorARGB8(int a, int r, int g, int b) {
        int value = (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0;
        return new Res_value(28, value, (String)null, (List)null);
    }

    public static Res_value newColorRGB8(int r, int g, int b) {
        int value = (r & 255) << 16 | (g & 255) << 8 | (b & 255) << 0;
        return new Res_value(29, value, (String)null, (List)null);
    }

    public static Res_value newColorARGB4(int a, int r, int g, int b) {
        int value = (a & 15) << 12 | (r & 15) << 8 | (g & 15) << 4 | (b & 15) << 0;
        return new Res_value(30, value, (String)null, (List)null);
    }

    public static Res_value newColorRGB4(int r, int g, int b) {
        int value = (r & 15) << 8 | (g & 15) << 4 | (b & 15) << 0;
        return new Res_value(31, value, (String)null, (List)null);
    }

    // 添加创建维度和分数的静态方法
    public static Res_value newDimension(float value, int unit) {
        int unitBits = (unit & COMPLEX_UNIT_MASK) << COMPLEX_UNIT_SHIFT;
        int valueBits = Float.floatToIntBits(value) & 0xFFFFFF00;
        return new Res_value(TYPE_DIMENSION, valueBits | unitBits, null, null);
    }

    public static Res_value newFraction(float value, int flag) {
        int flagBits = (flag & FRACTION_FLAG_MASK) << FRACTION_FLAG_SHIFT;
        int valueBits = Float.floatToIntBits(value) & 0xFFFF00FF;
        return new Res_value(TYPE_FRACTION, valueBits | flagBits, null, null);
    }
}